package cn.edu.nhic.nhcarsb.controller;

import cn.edu.nhic.nhcarsb.entity.Banner;
import cn.edu.nhic.nhcarsb.entity.R;
import cn.edu.nhic.nhcarsb.service.BannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/banner")
@Api(tags = "前端广告提供者")
public class BannerController extends BaseController{
    @Autowired
    private BannerService bannerService;

    @GetMapping("/{pno}/{psize}")
    @ApiOperation(value = "广告列表")
    public R list(@ApiParam(value = "页码") @PathVariable int pno,
                  @ApiParam(value = "页大小") @PathVariable int psize) {
        Page<Banner> page = new Page<>(pno, psize);
        QueryWrapper<Banner> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("border");//order by border desc
        Page<Banner> bannerPage = bannerService.page(page, queryWrapper);
        return R.success(bannerPage);
    }

}
